package com.ga01.controller;

import com.ga01.entity.Course;
import com.ga01.service.CourseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/courses")
public class CourseController {

    @Autowired
    private CourseService courseService;

    @GetMapping
    public List<Course> getAllCourses() {
        return courseService.list();
    }

    @GetMapping("/{id}")
    public Course getCourseById(@PathVariable Integer id) {
        return courseService.getById(id);
    }

    @PostMapping
    public boolean addCourse(@RequestBody Course course) {
        return courseService.save(course);
    }

    @PutMapping
    public boolean updateCourse(@RequestBody Course course) {
        return courseService.updateById(course);
    }

    @DeleteMapping("/{id}")
    public boolean deleteCourse(@PathVariable Integer id) {
        return courseService.removeById(id);
    }
}